package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: Bright
 * @Date: 2022-04-21 16:23
 * @Description: com.atguigu.srb.core.controller.admin
 * @version: 1.0
 */
@Slf4j
@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Resource
    BorrowerService borrowerService;

    @ApiOperation(value = "得到借款人列表")
    @GetMapping("/list/{page}/{limit}")
    public R getPageList(
            @ApiParam(value = "当前页码", required = true)
            @PathVariable Integer page,

            @ApiParam(value = "每页记录数", required = true)
            @PathVariable Integer limit,

            @ApiParam(value = "查询关键字")
            @RequestParam String keyword) {
        Page<Borrower> pageParam = new Page<>(page, limit);
        IPage<Borrower> pageModel = borrowerService.getPageList(pageParam, keyword);

        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation(value = "获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(
            @ApiParam(value = "借款id", required = true)
            @PathVariable Long id) {
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerVoById(id);

        return R.ok().data("borrowerDetailVO", borrowerDetailVO);

    }

    @ApiOperation(value = "积分存储")
    @PostMapping("/approval")
    public R approval(
            @ApiParam(value = "对象积分常数")
            @RequestBody BorrowerApprovalVO borrowerApprovalVO) {

        borrowerService.approval(borrowerApprovalVO);

        return R.ok();
    }


}
